package diamondRingServlet;

import diamondRingEntity.OrderGoods;
import diamondRingEntity.Shooping;
import diamondRingService.impl.DiamondRingServiceImpl;
import diamondRingService.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

//订单小项表新增信息
@WebServlet("/OrderGoodsInsertServlet")
public class OrderGoodsInsertServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        OrderServiceImpl bo=new OrderServiceImpl();
        DiamondRingServiceImpl bo2=new DiamondRingServiceImpl();
        int orderNumber=bo.orderFindId(request.getParameter("orderNumber"));
        List<Shooping> shoopingList=bo2.findGoods(Integer.parseInt(request.getParameter("userid")));
        int num=0;
        if (shoopingList!=null){
            for (Shooping og:
                    shoopingList ) {
                String GoodsName=og.getGoods().getSeries()+" "+og.getGoods().getStyle();
                System.out.println(GoodsName);
                OrderGoods orderGoods=new OrderGoods(GoodsName,og.getGoodsId(),orderNumber,og.getGoods().getTexture(),og.getSize(),og.getLettering());
                num=bo.orderGoodsInsert(orderGoods);
                System.out.println(num);
            }
        }
        PrintWriter out=response.getWriter();
        out.print(num);
        out.flush();
        out.close();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
    }
}
